public class code3 {
    public boolean isValid(String s) {
        int first = 0;
        int second = 0;
        int third = 0;
        for(char ch:s.toCharArray()) {
            switch (ch) {
                case '(': first++;break;
                case ')': first--;break;
                case '{': second++;break;
                case '}': second--;break;
                case '[': third++;break;
                case ']': third--;break;

            }
        }
        return first==0 && second==0 && third==0;

    }
}
